/*
@author: ty
@file: atm.go
@time: 2022/12/2 16:01
*/
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	fmt.Println("1、登录")
	fmt.Println("2、注册")
		var op string
		var option string
		var products_id string
		var num string
		var name string
		var passwd string
		fmt.Print("请输入你的选择(按q退出)：")
		fmt.Scan(&op)
		switch op {
		case "1":
			fmt.Print("请输入用户名:")
			fmt.Scanln(&name)
			fmt.Println("请输入密码:")
			fmt.Scanln(&passwd)
			result := login(name, passwd)
			if result {
				fmt.Println("登录成功")
				for true {
					menu()
					fmt.Println("请输入你的选择:")
					fmt.Scan(&option)
					if option == "1" {
						show()
					} else if option == "2" {
						fmt.Println("请输入要购买的商品号码:")
						fmt.Scan(&products_id)
						if _, ok := products[products_id]; ok {
							fmt.Println("请输入购买商品数量:")
							fmt.Scan(&num)
							add_car(name, products_id, num)
						}
					} else if option == "3" {
						checkout(name)
					} else if option == "4" {
						break
					}
				}
			} else{
				fmt.Println("登陆失败,用户名和密码错误")
			}
		case "2":
			fmt.Print("请输入用户名:")
			Read := bufio.NewReader(os.Stdin)
			name, _ := Read.ReadString('\n')
			fmt.Print("请输入密码:")
			passRead := bufio.NewReader(os.Stdin)
			passwd, _ := passRead.ReadString('\n')
			result := register(strings.Replace(name, "\n", "", -1), strings.Replace(passwd, "\n", "", -1))
			fmt.Println(result)
			if result {
				fmt.Println(user)
			}
		case "q":
			flag = 1
		}
	}
}
